home *** CD-ROM | disk | FTP | other *** search
/ Network PC / Network PC.iso / amiga utilities / communication / internet / amitcp3.0b / src.lha / src / amitcp / api / amiga_api.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-08  |  6.0 KB  |  218 lines

  1. /*
  2.  * $Id: amiga_api.h,v 3.7 1994/04/02 11:12:59 jraja Exp $
  3.  * 
  4.  * Copyright (c) 1993 AmiTCP/IP Group, <amitcp-group@hut.fi>
  5.  *                    Helsinki University of Technology, Finland.
  6.  *                    All rights reserved.
  7.  *
  8.  * Created: Tue Jan 26 20:35:28 1993 too
  9.  * Last modified: Sat Apr  2 14:12:06 1994 jraja
  10.  * 
  11.  * $Log: amiga_api.h,v $
  12.  * Revision 3.7  1994/04/02  11:12:59  jraja
  13.  * Added resolver variables, minor cleanup, some older fields has been
  14.  * changed, too.
  15.  *
  16.  * Revision 3.6  1994/03/29  12:56:35  ppessi
  17.  * Added SBTC_COMPAT43 tag
  18.  *
  19.  * Revision 3.5  1994/03/22  07:34:47  jraja
  20.  * Added fdCallback (function pointer for fd coordination with a link library)
  21.  * to the SocketBase.
  22.  *
  23.  * Revision 3.4  1994/01/20  02:12:49  jraja
  24.  * Changed baseErrno() to readErrnoValue().
  25.  *
  26.  * Revision 3.3  1994/01/18  19:18:52  jraja
  27.  * Added baseErrno(base) macro for errno reading/writing.
  28.  *
  29.  * Revision 3.2  1994/01/12  07:16:39  jraja
  30.  * Added Syslog() related variables to the library base.
  31.  *
  32.  * Revision 3.1  1994/01/04  14:20:11  too
  33.  * Added hErrno to SocketBase. Marker nextDToSearch to obsolete (not
  34.  * removed since it uses no extra space)
  35.  *
  36.  * Revision 1.28  1993/11/26  16:23:42  too
  37.  * added prototype for sendbreaktotasks()
  38.  *
  39.  * Revision 1.27  1993/06/07  12:37:20  too
  40.  * Changed inet_ntoa, netdatabase functions and WaitSelect() use
  41.  * separate buffers for their dynamic buffers
  42.  *
  43.  */
  44.  
  45. #ifndef AMIGA_API_H
  46. #define AMIGA_API_H
  47.  
  48. #ifndef EXEC_TYPES_H
  49. #error <exec/types.h> not included.
  50. #endif
  51.  
  52. #ifndef EXEC_LIBRARIES_H
  53. #error <exec/libraries.h> not included.
  54. #endif
  55.  
  56. #ifndef EXEC_SEMAPHORES_H
  57. #error <exec/semaphores.h> not included.
  58. #endif
  59.  
  60. #ifndef EXEC_TASKS_H
  61. #include <exec/tasks.h>
  62. #endif
  63.  
  64. #ifndef SYS_CDEFS_H
  65. #include <sys/cdefs.h>
  66. #endif
  67.  
  68. #ifndef SYS_TYPES_H
  69. #include <sys/types.h>
  70. #endif
  71.  
  72. #ifndef SYS_QUEUE_H
  73. #include <sys/queue.h>
  74. #endif
  75.  
  76. #ifndef API_RESOLV_H
  77. #include <api/resolv.h>
  78. #endif
  79.  
  80. struct newselbuf;
  81.  
  82. /*
  83.  * structure for holding size and address of some dynamically allocated buffers
  84.  * such as selitems for WaitSelect() and netdatabase entry structures
  85.  */
  86. struct DataBuffer {
  87.   int        db_Size;
  88.   void *    db_Addr;
  89. };
  90.  
  91. typedef int (* ASM fdCallback_t)(REG(d0) int fd, REG(d1) int action);
  92.  
  93. struct SocketBase {
  94.   struct Library    libNode;
  95. /* -- "Global" Errno -- */
  96.   BYTE            flags;
  97.   BYTE            errnoSize;                             /* 1, 2 or 4 */
  98.  /* -- now we are longword aligned -- */
  99.   UBYTE *        errnoPtr;                   /* this points to errno */
  100.   LONG            defErrno;
  101. /* Task pointer of owner task */
  102.   struct Task *        thisTask;
  103. /* task priority changes (WORDS so we keep structure longword aligned) */  
  104.   BYTE            myPri;        /* task's priority just after libcall */
  105.   BYTE            libCallPri;  /* task's priority during library call */
  106. /* note: not long word aligned at this point */
  107. /* -- descriptor sets -- */
  108.   WORD            dTableSize; /* long word aligned again */
  109.   struct socket    **    dTable;
  110.   fdCallback_t        fdCallback;
  111. /* AmiTCP signal masks */
  112.   ULONG            sigIntrMask;
  113.   ULONG            sigIOMask;
  114.   ULONG            sigUrgMask;
  115. /* -- these are used by tsleep()/wakeup() -- */
  116.   const char *        p_wmesg;
  117.   queue_chain_t     p_sleep_link;
  118.   caddr_t        p_wchan;               /* event process is awaiting */
  119.   struct timerequest *    tsleep_timer;
  120.   struct MsgPort *    timerPort;
  121. /* -- pointer to select buffer during Select() -- */
  122.   struct newselbuf *    p_sb;
  123. /* -- per process fields used by various 'library' functions -- */
  124. /* buffer for inet_ntoa */
  125.   char            inet_ntoa[20]; /* xxx.xxx.xxx.xxx\0 */
  126. /* -- pointers for data buffers that MAY be used -- */
  127.   struct DataBuffer    selitems;
  128.   struct DataBuffer    hostents;
  129.   struct DataBuffer    netents;
  130.   struct DataBuffer    protoents;
  131.   struct DataBuffer    servents;
  132. /* -- variables for the syslog (see netinclude:sys/syslog.h) -- */
  133.   UBYTE            LogStat;                                  /* status */
  134.   UBYTE            LogMask;                     /* mask for log events */
  135.   UWORD            LogFacility;                       /* facility code */
  136.   const char *        LogTag;               /* tag string for the log events */
  137. /* -- resolver variables -- */
  138.   LONG *        hErrnoPtr;
  139.   LONG            defHErrno;
  140.   LONG            res_socket;       /* socket used for resolver comm. */
  141.   struct state          res_state;
  142. };
  143.  
  144. /* 
  145.  * Socket base flags 
  146.  */
  147. #define SBFB_COMPAT43    0L        /* compat 43 code (without sockaddr_len) */
  148.  
  149. #define SBFF_COMPAT43   1L
  150.  
  151. /*
  152.  * macro for getting error value pointed by the library base. All but
  153.  * the lowest byte of the errno are assumed to stay zero. 
  154.  */
  155. #define readErrnoValue(base) ((base)->errnoPtr[(base)->errnoSize - 1])
  156.  
  157. extern struct SignalSemaphore syscall_semaphore;
  158. extern struct List releasedSocketList;
  159.  
  160. /*
  161.  *  Functions to put and remove application library to/from exec library list
  162.  */
  163. BOOL api_init(VOID);
  164. BOOL api_show(VOID);
  165. VOID api_hide(VOID);
  166. VOID api_setfunctions(VOID);
  167. VOID api_sendbreaktotasks(VOID);
  168. VOID api_deinit(VOID);
  169.  
  170. /* Function which set Errno value */
  171.  
  172. VOID writeErrnoValue(struct SocketBase *, int);
  173.  
  174. /*
  175.  * inline functions which changes (raises) task priority while it is
  176.  * executing library functions
  177.  */
  178.  
  179. static inline void ObtainSyscallSemaphore(struct SocketBase *libPtr)
  180. {
  181.   extern struct Task *AmiTCP_Task;
  182.  
  183.   ObtainSemaphore(&syscall_semaphore);
  184.   libPtr->myPri = SetTaskPri(libPtr->thisTask,
  185.                  libPtr->libCallPri = AmiTCP_Task->tc_Node.ln_Pri);
  186. }
  187.  
  188. static inline void ReleaseSyscallSemaphore(struct SocketBase *libPtr)
  189. {
  190.   if (libPtr->libCallPri != (libPtr->myPri = SetTaskPri(libPtr->thisTask,
  191.                             libPtr->myPri)))
  192.     SetTaskPri(libPtr->thisTask, libPtr->myPri);
  193.   ReleaseSemaphore(&syscall_semaphore);
  194. }
  195.  
  196. /*
  197.  * inline function for searching library base when taskpointer is known
  198.  */
  199.  
  200. static inline struct SocketBase *FindSocketBase(struct Task *task)
  201. {
  202.   extern struct List socketBaseList;
  203.   struct Node *libNode;
  204.  
  205.   Forbid();
  206.   for (libNode = socketBaseList.lh_Head; libNode->ln_Succ;
  207.        libNode = libNode->ln_Succ)
  208.     if (((struct SocketBase *)libNode)->thisTask == task) {
  209.       Permit();
  210.       return (struct SocketBase *)libNode;
  211.     }
  212.   /* here if Task wasn't in socketBaseList */
  213.   Permit();
  214.   return NULL;
  215. }
  216.  
  217. #endif /* !AMIGA_API_H */
  218.